<template>
	<!-- 我的 -->
  <view class="mine-container" :style="{height: `${windowHeight}px`}">
    <!--顶部个人信息栏-->
    <view class="header-section">
      <view class="flex padding justify-between">
        <view class="flex align-center">
          <view v-if="!avatar" class="cu-avatar xl round bg-white">
            <view class="iconfont icon-people text-gray icon"></view>
          </view>
<!--          <image v-if="avatar" @click="handleToAvatar" :src="avatar" class="cu-avatar xl round" mode="widthFix">
          </image> -->
          <view v-if="!name" @click="handleToLogin" class="login-tip">
            点击登录
          </view>
          <view v-if="name" @click="handleToInfo" class="user-info">
            <view class="u_title">
              用户名：{{ name }}
            </view>
          </view>
        </view>
<!--        <view @click="handleToInfo" class="flex align-center">
          <text>个人信息</text>
          <view class="iconfont icon-right"></view>
        </view> -->
      </view>
    </view>

   
   <view class="menu-list">
      <!-- <view class="list-cell list-cell-arrow" @click="startScan">
        <view class="menu-item-box">
          <view class="iconfont icon-user menu-icon"></view>
          <view>扫码入库</view>
        </view>
      </view>
	  <view class="list-cell list-cell-arrow" @click="startScans">
	    <view class="menu-item-box">
	      <view class="iconfont icon-user menu-icon"></view>
	      <view>药品扫码入库</view>
	    </view>
	  </view>
   <view class="list-cell list-cell-arrow" @click="startScansss">
     <view class="menu-item-box">
       <view class="iconfont icon-user menu-icon"></view>
       <view>随货同行单(测试简便进入)</view>
     </view>
   </view>
   
      <view class="list-cell list-cell-arrow" @click="handleToSetting">
        <view class="menu-item-box">
          <view class="iconfont icon-setting menu-icon"></view>
          <view>应用设置</view>
        </view>
      </view> -->
	  
	  
	  <!-- 宫格组件 -->
	  <uni-section title="功能列表" ></uni-section>
<!-- 	  <view class="list-cell list-cell-arrow" v-for="menu in menuList" :key="menu.id" :index='menuList.length'>
	    <view class="menu-item-box" @click="changeGrid(menu)">
	      <view class="iconfont icon-setting menu-icon"></view>
	      <view>{{menu.name}}</view>
	    </view> -->
			  <view class="list-cell list-cell-arrow">
			    <view class="menu-item-box" @click="handleToSetting()">
			      <view class="iconfont icon-setting menu-icon"></view>
			      <view>设置</view>
			    </view>
		
	  </view>

	  
    </view>

    </view>
  </view>
</template>

<script>
  import storage from '@/utils/storage'
import * as SupplierSendOrderApi from '@/api/suppliersendorder/inde.js'; // 随货同行单
  export default {
	   onLoad() {
	  		this.getInfo()
	  		 },
    data() {
      return {
		menuList:'',
        name: this.$store.state.user.name,
        version: getApp().globalData.config.appInfo.version
      }
    },
    computed: {
      avatar() {
        return this.$store.state.user.avatar
      },
      windowHeight() {
        return uni.getSystemInfoSync().windowHeight - 50
      }
    },
    methods: {
		changeGrid(e) {
			 uni.navigateTo({
			 	url:'/'+e.path
			 }) 
		},
	  async getInfo(){
	  	 this.menuList = this.$store.getters.menus[0].children
		 //.menus[0].children[0].children、、
		 
		 console.log("菜单啊")
		 console.log(this.menuList)
		 console.log("菜单啊",this.$store.getters.menus[0])
	    },
      handleToInfo() {
        this.$tab.navigateTo('/pages/mine/info/index')
      },

      handleToSetting() {
        this.$tab.navigateTo('/pages/mine/setting/index')
      },
      handleToLogin() {
        this.$tab.reLaunch('/pages/login')
      },
      handleToAvatar() {
        this.$tab.navigateTo('/pages/mine/avatar/index')
      },
      handleLogout() {
        this.$modal.confirm('确定注销并退出系统吗？').then(() => {
          this.$store.dispatch('LogOut').then(() => {
            this.$tab.reLaunch('/pages/index')
          })
        })
      },


      handleJiaoLiuQun() {
        this.$modal.showToast('微信搜索 naidaguo 后，添加好友后拉你进技术交流群')
      },
      handleBuilding() {
        this.$modal.showToast('模块建设中~')
      },
	      startScan() {
	        uni.scanCode({
	          success: (res) => {
	            this.handleScanResult(res.result);
	          },
	          fail: (err) => {
	            console.error('扫描失败:', err);
				console.Console('扫描失败:', err);
	          }
	        });
	      },
		  startScans() {
	        uni.scanCode({
	          success: (res) => {
	            this.handleScanResult(res.result);
	          },
	          fail: (err) => {
	            console.error('扫描失败:', err);
				console.Console('扫描失败:', err);
	          }
	        });

		      },
		  startScansss() {
		    uni.reLaunch({
		    url: `/pages/scanCodes/index?data=1`
		    });
		  },
handleScanResult(scanData) {
  console.log('扫描结果', scanData);
  // 跳转暂时拿出来测试
  uni.navigateTo({
    url: `/pages/scanCode/index?data=${encodeURIComponent(scanData)}`
  });
  try {
    const id = scanData;
     SupplierSendOrderApi.getSupplierSendOrder(id).then(res => {
      console.log('API调用结果', res.data.statusTwo);

      // 判断扫描结果是不是随货同行单，为空不属于随货同行单
      if (res.data == null) {
        uni.showToast({
          title: '请扫描正确的随货同行单',
          icon: 'none',
          duration: 2000
        });
      } else if (res.data.statusTwo === '1') {
        uni.showToast({
          title: '该随货同行单已进行过入库操作，不可以重复操作',
          icon: 'none',
          duration: 5000
        });
      } else if(res.data.statusTwo === '0') {
		  // 弹窗测试验证  需要删除
		  uni.showToast({
		    title: '正常操作随货同行单',
		    icon: 'none',
		    duration: 5000
		  });
// mki    BHG      
 uni.reLaunch({
          url: `/pages/scanCode/index?data=${encodeURIComponent(scanData)}`
        });
      }
    }).catch(error => {
    console.error(error)
    });
  } finally {
    // 这里可以添加一些清理代码，如果需要的话
  }
},
handleScanResultss(scanData) {
  console.log('扫描结果', scanData);
  // 跳转暂时拿出来测试
  uni.navigateTo({
    url: `/pages/scanCodes/index?data=${encodeURIComponent(scanData)}`
  });
  try {
    const id = scanData;
     SupplierSendOrderApi.getSupplierSendOrder(id).then(res => {
      console.log('API调用结果', res.data.statusTwo);

      // 判断扫描结果是不是随货同行单，为空不属于随货同行单
      if (res.data == null) {
        uni.showToast({
          title: '请扫描正确的随货同行单',
          icon: 'none',
          duration: 2000
        });
      } else if (res.data.statusTwo === '1') {
        uni.showToast({
          title: '该随货同行单已进行过入库操作，不可以重复操作',
          icon: 'none',
          duration: 5000
        });
      } else if(res.data.statusTwo === '0') {
		  // 弹窗测试验证  需要删除
		  uni.showToast({
		    title: '正常操作随货同行单',
		    icon: 'none',
		    duration: 5000
		  });
// mki    BHG      
 uni.reLaunch({
          url: `/pages/scanCode/index?data=${encodeURIComponent(scanData)}`
        });
      }
    }).catch(error => {
    console.error(error)
    });
  } finally {
    // 这里可以添加一些清理代码，如果需要的话
  }
},
	  

    }
  }
</script>

<style lang="scss">
  page {
    background-color: #f5f6f7;
  }
.uni-grid-item {
  width: 100%; /* 设置你想要的宽度 */
}
  .mine-container {
    width: 100%;
    height: 100%;


    .header-section {
      padding: 15px 15px 45px 15px;
      background-color: #3c96f3;
      color: white;

      .login-tip {
        font-size: 18px;
        margin-left: 10px;
      }

      .cu-avatar {
        border: 2px solid #eaeaea;

        .icon {
          font-size: 40px;
        }
      }

      .user-info {
        margin-left: 15px;

        .u_title {
          font-size: 18px;
          line-height: 30px;
        }
      }
    }

    .content-section {
      position: relative;
      top: -50px;

      .mine-actions {
        margin: 15px 15px;
        padding: 20px 0px;
        border-radius: 8px;
        background-color: white;

        .action-item {
          .icon {
            font-size: 28px;
          }

          .text {
            display: block;
            font-size: 13px;
            margin: 8px 0px;
          }
        }
      }
    }
  }
</style>
